from neo4j import GraphDatabase

# 连接到Neo4j数据库
uri = "bolt://localhost:7687"
user = "neo4j"
password = "password"

# 创建驱动实例
driver = GraphDatabase.driver(uri, auth=(user, password))

def check_all_relationships():
    with driver.session() as session:
        # 获取所有关系类型
        rel_types_query = """
        CALL db.relationshipTypes() YIELD relationshipType
        RETURN relationshipType
        ORDER BY relationshipType
        """
        rel_types_result = session.run(rel_types_query)
        
        print("=== Neo4j数据库中的所有关系类型 ===")
        rel_types = []
        for record in rel_types_result:
            rel_type = record["relationshipType"]
            rel_types.append(rel_type)
            print(f"- {rel_type}")
        
        # 获取每种关系类型的数量
        print("\n=== 每种关系类型的数量 ===")
        for rel_type in rel_types:
            count_query = f"""
            MATCH ()-[r:{rel_type}]->()
            RETURN count(r) as count
            """
            count_result = session.run(count_query)
            count = count_result.single()["count"]
            print(f"{rel_type}: {count}个关系")
        
        # 检查原始关系名称的分布
        print("\n=== 原始关系名称的分布 ===")
        for rel_type in rel_types:
            original_names_query = f"""
            MATCH ()-[r:{rel_type}]->()
            RETURN DISTINCT r.original_relation as original_name, count(*) as count
            ORDER BY count DESC
            """
            original_names_result = session.run(original_names_query)
            
            print(f"\n关系类型 {rel_type} 的原始名称:")
            for record in original_names_result:
                original_name = record["original_name"]
                count = record["count"]
                print(f"  {original_name}: {count}个")

# 执行查询并关闭连接
check_all_relationships()
driver.close() 